#include <iostream>
#include <vector>
#include <algorithm>
#define MAXN 2505
using namespace std;
int C, L;
typedef pair<int, int> range;
typedef pair<int, int> liquid;
range cows[MAXN];
liquid liq[MAXN];

bool cmp(range r1, range r2) {
    if (r1.second == r2.second) return r1.first < r2.first;
    return r1.second < r2.second;
}

void solve();
int main() {
    cin >> C >> L;
    for (int i = 0; i < C; i++) {
        cin >> cows[i].first >> cows[i].second;
    }
    for (int i = 0; i < L; i++) {
        cin >> liq[i].first >> liq[i].second;
    }
    solve();
}



void solve() {
    sort(cows, cows + C, cmp);
    sort(liq, liq + L);
    int res = 0;
    for (int i = 0; i < C; i++) {
        int minx = cows[i].first, maxx = cows[i].second;
        for (int j = 0; j < L; j++) {
            if (liq[j].second > 0 && liq[j].first >= minx && liq[j].first <= maxx) {
                liq[j].second -= 1;
                res += 1;
                break;
            }
        }
    }
    cout << res << endl;
}


